<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<title>找回密码</title>
<script type="text/javascript">
</script>
<script type="text/javascript" src="__PUBLIC__/index/js/jquery-1.8.1.js"></script>

<!-- 引入微信的js -->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

<link href="__PUBLIC__/index/css/sign2.css" type="text/css" rel="stylesheet">
<link href="__PUBLIC__/index/css/css.css" type="text/css" rel="stylesheet">

<script type="text/javascript" src="__PUBLIC__/index/js/alert.js"></script>
</head>

<body>
  <div class="layout">
       <span><img src="__PUBLIC__/index/image/logo.png" width="120" height="35" /></span>
            <form method="post" id="register">
            <ul>
                <p id="err_msg"></p>
                <li><i class="un"></i><input class="username" type="text" name="phone" id="verify_btn" required="required" placeholder="请输入你的手机号" /></li>
                <li><i class="yz"></i><input class="yzm" type="text" name="verify" id="verify"  placeholder="请输入验证码" /><input type="button" id="send" class="send"  value="获取验证码" /></li>
                <!-- 表单令牌验证 begin-->
                <input type="hidden" value="{$arr}" id="token" name="token">
                <!-- 表单令牌验证 end-->
                <input type="hidden" value="{$res}" id="openid" name="openid" />

                <li><i class="pw"></i><input class="pwd" type="password" name="password" id="pas1" placeholder="请输入您的新密码" /></li>
                <li><i class="pw2"></i><input class="pwd2" type="password" id="pas2" placeholder="请确认新密码" /></li>
               
            </ul>
                <div class="reg_btn">
                  <button type="button" class="submit" onClick="checksubmit();">确认</button>     
                </div>
            </form>
        </div>
</body>
</html>
<script type="text/javascript">
// 去除微信右上角的点点点
wx.config({
    debug: false,
    appId: "{$sign.appId}",
    timestamp:"{$sign.timestamp}",
    nonceStr:"{$sign.nonceStr}",
    signature:"{$sign.signature}",
    jsApiList: [
        'wx.hideOptionMenu',
      ]
});
wx.checkJsApi({
    jsApiList: [
        'getLocation'
    ],
    success: function (res) {
  
        if (res.checkResult.getLocation == false) {
            alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
            return;
        }
    }
});
//隐藏微信右上角
wx.ready(function () {
   wx.hideOptionMenu();
    
});

$(document).ready(function(e) {
  var height=document.documentElement.clientHeight;
  var width=document.documentElement.clientWidth;
  $(".layout").css({"height":height,"width":width});

});

  
  function checksubmit(){
    var phone = $('#verify_btn').val();
    var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;
       if(!reg.test(phone)) 
          { 
            hint('请输入有效的手机号码!');
             return false; 
         }

    var v=$("#verify").val();
    if (phone=="" || v=="") {
      hint("手机号或者验证码不能为空");
      return false;
    };

    //验证密码是否正确
    var pas1,pas2;
    pas1=document.getElementById("pas1").value;
    pas2=document.getElementById("pas2").value;
    if(pas1.length<6){
      hint("密码必须大于6位，请重新输入！"); 

    return;
    }
    if(pas1.length>12){
      hint("密码必须小于12位，请重新输入！"); 

    return;
    }
    if(!(pas1==pas2 && pas2!='')){
      
    hint("两次输入的密码不一致，请重新输入！");
    return;
    }
    var openid=$("#openid").val();
    var data={
      phone:phone,
      num:v,
      openid:openid,
    }
    $.post('{:U("Forget/check")}',data,function(obj){
      if (obj.c=="openid") {
      hint(obj.m);
      return false;
      };
      if (obj.c=="shixiao") {
        hint(obj.m);
        return false;
      };
      if (obj.c=="error") {
        hint(obj.m);
        return false;
      };
      if (obj.c=="yes") {

         $.ajax({
                cache: true,
                type: "POST",
                url:'{:U("Forget/register")}',
                data:$('#register').serialize(),
                async: false,
                error: function(request) {
                    alert("失败");
                },
                success: function(data) {
                    hint('修改成功');
                    /*wx.ready(function () {
                      wx.closeWindow();
                      });*/
                    window.location.href='http://sunwayuchoice.com/index.php/Enter/index';
                   }
               });
      };
    });
  }

  var wait=60;  
  function time(o) {  
          if (wait == 0) {  
              o.removeAttribute("disabled");            
              o.value="获取验证码";  
              wait = 60;  
          } else {  
              o.setAttribute("disabled", true);  
              o.value="重新发送(" + wait + ")";  
              wait--;  
              setTimeout(function() {  
                  time(o)  
              },  
              1000)  
          }  
      }  
  document.getElementById("send").onclick=function(){
    var phone=$('#verify_btn').val();
    var token=$('#token').val();
    var data={
      phone:phone,
      token:token,
      }
      var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;
       if(!reg.test(phone)) 
          { 
             hint('请输入有效的手机号码!'); 
         
             return false; 
         }else{
        $.post('{:U("Forget/msg")}',data,function(obj){
          if (obj.s=="no") {
            hint(obj.m);
          };
          if (obj.s=="ok") {
            hint(obj.m);
          };
          if (obj.s=="check") {
          hint(obj.m);
          };
          if (obj.s=="fail") {
            hint(obj.m);
          };
          });
      }

      time(this);

  } 

</script>
